package com.health.department.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.enums.BusinessType;
import com.health.department.domain.MedicalDepartment;
import com.health.department.service.IMedicalDepartmentService;
import com.health.common.utils.poi.ExcelUtil;
import com.health.common.core.page.TableDataInfo;

/**
 * 科室管理Controller
 * 
 * @author ruoyi
 * @date 2025-10-26
 */
@RestController
@RequestMapping("/department/departments")
public class MedicalDepartmentController extends BaseController
{
    @Autowired
    private IMedicalDepartmentService medicalDepartmentService;

    /**
     * 查询科室管理列表
     */
    @PreAuthorize("@ss.hasPermi('department:departments:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicalDepartment medicalDepartment)
    {
        startPage();
        List<MedicalDepartment> list = medicalDepartmentService.selectMedicalDepartmentList(medicalDepartment);
        return getDataTable(list);
    }

    /**
     * 导出科室管理列表
     */
    @PreAuthorize("@ss.hasPermi('department:departments:export')")
    @Log(title = "科室管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicalDepartment medicalDepartment)
    {
        List<MedicalDepartment> list = medicalDepartmentService.selectMedicalDepartmentList(medicalDepartment);
        ExcelUtil<MedicalDepartment> util = new ExcelUtil<MedicalDepartment>(MedicalDepartment.class);
        util.exportExcel(response, list, "科室管理数据");
    }

    /**
     * 获取科室管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('department:departments:query')")
    @GetMapping(value = "/{departmentId}")
    public AjaxResult getInfo(@PathVariable("departmentId") Long departmentId)
    {
        return success(medicalDepartmentService.selectMedicalDepartmentByDepartmentId(departmentId));
    }

    /**
     * 新增科室管理
     */
    @PreAuthorize("@ss.hasPermi('department:departments:add')")
    @Log(title = "科室管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicalDepartment medicalDepartment)
    {
        return toAjax(medicalDepartmentService.insertMedicalDepartment(medicalDepartment));
    }

    /**
     * 修改科室管理
     */
    @PreAuthorize("@ss.hasPermi('department:departments:edit')")
    @Log(title = "科室管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicalDepartment medicalDepartment)
    {
        return toAjax(medicalDepartmentService.updateMedicalDepartment(medicalDepartment));
    }

    /**
     * 删除科室管理
     */
    @PreAuthorize("@ss.hasPermi('department:departments:remove')")
    @Log(title = "科室管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{departmentIds}")
    public AjaxResult remove(@PathVariable Long[] departmentIds)
    {
        return toAjax(medicalDepartmentService.deleteMedicalDepartmentByDepartmentIds(departmentIds));
    }
}
